<template>
  <div class="content">
    <!-- 头部 -->
    <div class="header">
      <van-icon name="arrow-left" @click="goBack" />
      <span>添加地址</span>
    </div>

    <van-address-edit
      :area-list="areaList"
      show-postal
      show-delete
      show-set-default
      show-search-result
      :search-result="searchResult"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @delete="onDelete"
      @change-detail="onChangeDetail"
    />
  </div>
</template>

<script>
import { Toast } from "vant";
import axios from '@/utils/service';

export default {
  data() {
    return {
      areaList: {},
      searchResult: [],
    };
  },
/*   created(){
    // 有bug
    axios({
      method:"post",
      url:"/api/address/add",
      data:{
        userid:localStorage.getItem("userid"),
        name:"this.name",
        tel:localStorage.getItem("tel"),
        province:"",
        city:"",
        county:"",
        addressDetail:"",
        isDefault:""
      }
    })
  }, */
  methods: {
    goBack() {
      this.$router.back();
    },
    onSave() {
      Toast("save");
    },
    onDelete() {
      Toast("delete");
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: "黄龙万科中心",
            address: "杭州市西湖区",
          },
        ];
      } else {
        this.searchResult = [];
      }
    },
  },
  
};
</script>

<style scoped>
.header {
  height: 3.5rem;
  text-align: center;
  font-size: 1.3rem;
  line-height: 3.5rem;
  border-bottom: 2px solid gray;
}
.van-icon {
  float: left;
  padding-left: 10px;
  line-height: 3.5rem;
  color: rgb(24, 24, 64);
}
</style>